package com.wfy.common.entity;

import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: wangxindong
 * Date: 2017/9/27
 * Time: 09:11
 */
public class Result implements Serializable {

    // ================================================================
    // Constants
    // ================================================================

    private static final long serialVersionUID = 1L;

    // ================================================================
    // Fields
    // ================================================================

    private String msg;
    private int code;
    private int count;
    private Object data;

    // ================================================================
    // Constructors
    // ================================================================

    public Result() {

    }

    public Result(String msg, int code, int count, Object data) {
        this.msg = msg;
        this.code = code;
        this.count = count;
        this.data = data;
    }

    public Result(Builder builder) {
        this.msg = builder.msg;
        this.code = builder.code;
        this.count = builder.count;
        this.data = builder.data;
    }

    // ================================================================
    // Methods from/for super Interfaces or SuperClass
    // ================================================================

    @Override
    public String toString() {
        return "Result{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                ", count=" + count +
                ", data=" + data +
                '}';
    }


    // ================================================================
    // Public or Protected Methods
    // ================================================================


    // ================================================================
    // Getter & Setter
    // ================================================================

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    // ================================================================
    // Private Methods
    // ================================================================


    // ================================================================
    // Inner or Anonymous Class
    // ================================================================

    public static class Builder {
        private String msg;
        private int code;
        private int count;
        private Object data;

        public Builder() {
        }

        public Builder(final String msg, final int code, final int count, final Object data) {
            this.msg = msg;
            this.code = code;
            this.count = count;
            this.data = data;
        }

        public Builder setMsg(String msg) {
            this.msg = msg;
            return this;
        }

        public Builder setCode(int code) {
            this.code = code;
            return this;
        }

        public Builder setCount(int count) {
            this.count = count;
            return this;
        }

        public Builder setData(Object data) {
            this.data = data;
            return this;
        }

        public Result build() {
            return new Result(this);
        }
    }

    // ================================================================
    // Test Methods
    // ================================================================

    public static void main(String[] args) {
        Result.Builder builder = new Builder();
        builder.setCode(1);
        builder.setCount(1);
        builder.setData("1234");
        builder.setMsg("success");
        Result result = builder.build();
        System.out.println(result);
    }

}
